var vo={};
var columns=[];
$(function(){
	var openWindow=window.document;
	$("#listReject").height($(openWindow).height()-$(openWindow).height()*0.05);
	$("#listReject").datagrid({
					url:'/rejectcount/getReject',
					title:'驳回返款列表',
					method:'get',
					pagination:true,
					pageList: [10,20,50,200],
					loadMsg:'加载中......',
					nowrap:true,
					showFooter:true,
					columns:[[ 
					        {field:'ck',checkbox:true},
					        {field:'shopid',title:'门店编号', align:'left',width:100,sortable:true},
							{field:'shopname',title:'门店名称', align:'left',width:100},
							{field:'dealerid',title:'经销商编号', align:'left',width:100,sortable:true},
							{field:'dealername',title:'经销商名称', align:'left',width:100},
							{field:'counttotal',title:'统计金额', align:'left',width:100},
							{field:'cmonth',title:'统计月份', align:'left',width:80},
							{field:'counttime',title:'统计时间', align:'left',width:130,sortable:true,formatter:function(value,row,index){
								 var datetime=Common.formatterDate2(value);
								 return datetime;
							}},
							{field:'countname',title:'统计人', align:'left',width:100},
							{field:'rejreason',title:'驳回原因', align:'left',width:100},
					]],
				});
	$("#listReject").datagrid({
		toolbar: '#tb'
	});
});
/**
 * 重新统计
 */
function reCount(){
	var rows=$("#listReject").datagrid('getSelections');
	if(rows.length<=0){
		$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	$.messager.confirm('重新统计','您确定要重新统计驳回数据吗？',function(data){
		if(data){
			var ids=[];
			for(var i=0;i<rows.length;i++){
				var id={};
				id.shopid=rows[i].shopid;
				id.cmonth=rows[i].cmonth;
				ids.push(id);
			}
			$.ajax({
		         type: 'GET',
		         dataType: "json",
		         data:{"ids":ids},
		         url: '/rejectcount/recount',
		         success: function (data) {
		        	 if(data.code==200){
							$.messager.alert("成功","统计成功",'info',function(){
								$("#listReject").datagrid('load',null);
							});
						}
						else{
							$.messager.alert("失败","统计失败："+data.msg,'error');
						}
					},
					error:function(data){
						$.messager.alert("失败","统计失败：",'error');
					}
		     })
		}
	})
}
/**
 * 保存统计数据
 */
function saveCount(){
	var rows=$("#listReject").datagrid('getSelections');
	if(rows.length<=0){
		$.messager.alert('错误','选中的记录为空','error');
		return;
	}
	$.messager.confirm('重新统计','您确定要保存统计数据吗？',function(data){
		if(data){
			var ids='';
			for(var i=0;i<rows.length;i++){
				ids+=rows[i].id+',';
			}
			$.ajax({
		         type: 'GET',
		         dataType: "json",
		         data:{ids:ids},
		         url: '/rejectcount/saveReject',
		         success: function (data) {
		        	 if(data.code==200){
							$.messager.alert("成功","保存成功",'info',function(){
								$("#listReject").datagrid('load',null);
							});
						}
						else{
							$.messager.alert("失败","保存失败："+data.msg,'error');
						}
					},
					error:function(data){
						$.messager.alert("失败","保存失败：",'error');
					}
		     })
		}
	})
}